package com.example.service.impl;

import com.example.common.Result;
import com.example.entity.HnyyPurRebateSaleHx;
import com.example.entity.HnyyPurRebateSaleHxLines;
import com.example.entity.VHnyyPurRebateSaleList;
import com.example.mapper.AccountMapper;
import com.example.service.AccountService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountMapper accountMapper;
    @Override
    public PageInfo<VHnyyPurRebateSaleList> getData(VHnyyPurRebateSaleList vHnyyPurRebateSaleList, String comPartyId) {
        // 开启分页查询
        PageHelper.startPage(vHnyyPurRebateSaleList.getPageNum(), vHnyyPurRebateSaleList.getPageSize());
        List<VHnyyPurRebateSaleList> basicInfos = accountMapper.getData(vHnyyPurRebateSaleList,comPartyId);
        return PageInfo.of(basicInfos);
    }

    @Override
    public int updateAmt(String id, String rebAmt, String comPartyId, String saler) {
        return accountMapper.updateAmt(id, rebAmt, comPartyId,saler);
    }

    @Override
    public Long apply(String comPartyId, String saler, String venderId,String purNo,String Id,String applyAmt) {
        Map<String, Object> param = new HashMap<>();
        param.put("comPartyId", comPartyId);
        param.put("creater", saler);
        param.put("venderId", venderId);
        param.put("purNo", purNo);
        accountMapper.apply(param);
        accountMapper.updateRebateListAmt(Id,applyAmt);
        return (Long)param.get("id"); // 返回主键
    }

    @Override
    public int applyHx(HnyyPurRebateSaleHxLines hxLines) {
        return accountMapper.applyHx(hxLines);
    }

    @Override
    public PageInfo<HnyyPurRebateSaleHx> getHxList(Integer pageNum, Integer pageSize, String creater, String venderId, String startDate, String endDate, String comPartyId,String key) {
        // 开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        List<HnyyPurRebateSaleHx> basicInfos = accountMapper.getHxList(creater, venderId, startDate, endDate,comPartyId,key);
        return PageInfo.of(basicInfos);
    }

    @Override
    public VHnyyPurRebateSaleList getHxListById(String id) {
        return accountMapper.getHxListById(id);
    }

    @Override
    public int saleCheck(String id, String memo, String key, String saler) {
        int x=accountMapper.saleCheck(id, memo, key, saler);
        if(Objects.equals(key, "4")){
            accountMapper.updateRebateListAmtCancel(id);
        }
        return x;

    }

}
